<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class sys_relate_manage extends CI_Controller {


	public function __construct() {
		session_start();
		parent::__construct();
	}

	public function  index(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		$this->load->library("common/right_manage");
		$data['update_relate']	=false;
		if ($this->right_manage->check_right("update_relate")) {
			$data['update_relate']	=true;
		}
		$data['delete_relate']	=false;
		if ($this->right_manage->check_right("delete_relate")) {
			$data['delete_relate']=true;
		}
		$data['add_relate']	=false;
		if ($this->right_manage->check_right("add_relate")) {
			$data['add_relate']	=true;
		}
		$data['query_relate']	=false;
		if ($this->right_manage->check_right("query_relate")) {
			$data['query_relate']	=true;
		}
		
		

		$this->load->library("sys/media_type");
		$data['media_type_list'] 	=$this->media_type->query_media_type_list();
		$data['num']				=$this->media_type->query_media_type_num();

		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/sys_relate_manage?",$data['num']);
		$this->load->view("sys/relate/relate_main",$data);
	}

	public function add_media_type(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->view("sys/relate/add_media_type",$data);
	}

	public function save_media_type(){

		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		
		
		$media_type['media_type_name'] =trim($this->input->post("media_type_name"));
		$media_type['create_by']		=$_SESSION['user_name'];
		$media_type['create_time']	=date("Y-m-d H:i:s");
		$media_type['modify_by']		=$_SESSION['user_name'];
		$media_type['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/media_type");
		$result =$this->media_type->save_media_type($media_type);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function edit_media_type(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$media_type_id =$this->input->get("media_type_id");
		$this->load->library("sys/media_type");
		$data['media_type_info']=$this->media_type->query_media_type_info($media_type_id);

		$this->load->view("sys/relate/edit_media_type",$data);
	}

	public function update_media_type(){

		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$media_type_id =$this->input->post('media_type_id');
		$media_type['media_type_name'] =trim($this->input->post("media_type_name"));
		$media_type['modify_by']		=$_SESSION['user_name'];
		$media_type['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/media_type");
		$result =$this->media_type->update_media_type($media_type,$media_type_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_media_type() {
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_relate",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		
		$this->load->library("sys/media_type");
		$media_type_id	= intval($this->input->get('media_type_id'));
		$this->media_type->set_delete_media_type($media_type_id);
		echo "<script>history.go(-1)</script>";
	}
	
	public function crafts_list(){


		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
		
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		
		$this->load->library("common/right_manage");
		$data['update_relate']	=false;
		if ($this->right_manage->check_right("update_relate")) {
			$data['update_relate']	=true;
		}
		$data['delete_relate']	=false;
		if ($this->right_manage->check_right("delete_relate")) {
			$data['delete_relate']=true;
		}
		$data['add_relate']	=false;
		if ($this->right_manage->check_right("add_relate")) {
			$data['add_relate']	=true;
		}
		$data['query_relate']	=false;
		if ($this->right_manage->check_right("query_relate")) {
			$data['query_relate']	=true;
		}
		
		
		$this->load->library("sys/crafts");
		$data['crafts_list'] 	=$this->crafts->query_crafts_list();
		$data['num']			=$this->crafts->query_crafts_num();
		
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/sys_relate_manage/crafts_list?",$data['num']);
		
		$this->load->view("sys/relate/crafts_list",$data);
	}
	public function add_crafts(){
	
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		
	
		$this->load->view("sys/relate/add_crafts",$data);
	}
	public function save_crafts(){
	
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
	
		$crafts['crafts_name'] =trim($this->input->post("crafts_name"));
		$crafts['create_by']		=$_SESSION['user_name'];
		$crafts['create_time']	=date("Y-m-d H:i:s");
		$crafts['modify_by']		=$_SESSION['user_name'];
		$crafts['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/crafts");
		$result =$this->crafts->save_crafts($crafts);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function edit_crafts(){
	
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
	
		$crafts_id =$this->input->get("crafts_id");
		$this->load->library("sys/crafts");
		$data['crafts_info']=$this->crafts->query_crafts_info($crafts_id);
	
		$this->load->view("sys/relate/edit_crafts",$data);
	}
	
	public function update_crafts(){
	
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
	
		$crafts_id =$this->input->post('crafts_id');
		$crafts['crafts_name'] 	=trim($this->input->post("crafts_name"));
		$crafts['modify_by']	=$_SESSION['user_name'];
		$crafts['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/crafts");
		$result =$this->crafts->update_crafts($crafts,$crafts_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	
	public function delete_crafts() {
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_relate",$_SESSION['user_id'])) {

			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		
		
		$this->load->library("sys/crafts");
		$crafts_id	= intval($this->input->get('crafts_id'));
		$this->crafts->set_delete_crafts($crafts_id);
		echo "<script>history.go(-1)</script>";
	}
	
	public function corner_case_list() {

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
		
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['update_relate']	=false;
		if ($this->right_manage->check_right("update_relate")) {
			$data['update_relate']	=true;
		}
		$data['delete_relate']	=false;
		if ($this->right_manage->check_right("delete_relate")) {
			$data['delete_relate']=true;
		}
		$data['add_relate']	=false;
		if ($this->right_manage->check_right("add_relate")) {
			$data['add_relate']	=true;
		}
		$data['query_relate']	=false;
		if ($this->right_manage->check_right("query_relate")) {
			$data['query_relate']	=true;
		}
		
		
		$this->load->library("sys/corner_case");
		$data['corner_case_list'] 	=$this->corner_case->query_corner_case_list();
		$data['num']				=$this->corner_case->query_corner_case_num();
		
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/sys_relate_manage/corner_case_list?",$data['num']);
		
		$this->load->view("sys/relate/corner_case_list",$data);
	}
	
	public function add_corner_case(){
	
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
	
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		
		$this->load->view("sys/relate/add_corner_case",$data);
	}
	
	public function save_corner_case(){
	
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
	
		$corner_case['corner_case_name'] =trim($this->input->post("corner_case_name"));
		$corner_case['create_by']		=$_SESSION['user_name'];
		$corner_case['create_time']	=date("Y-m-d H:i:s");
		$corner_case['modify_by']		=$_SESSION['user_name'];
		$corner_case['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/corner_case");
		$result =$this->corner_case->save_corner_case($corner_case);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function edit_corner_case(){
	
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
	
		$corner_case_id =$this->input->get("corner_case_id");
		$this->load->library("sys/corner_case");
		$data['corner_case_info']=$this->corner_case->query_corner_case_info($corner_case_id);
	
		$this->load->view("sys/relate/edit_corner_case",$data);
	}
	
	public function update_corner_case(){
	
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
	
		$corner_case_id =$this->input->post('corner_case_id');
		$corner_case['corner_case_name'] 	=trim($this->input->post("corner_case_name"));
		$corner_case['modify_by']	=$_SESSION['user_name'];
		$corner_case['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/corner_case");
		$result =$this->corner_case->update_corner_case($corner_case,$corner_case_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	
	public function delete_corner_case() {
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_relate",$_SESSION['user_id'])) {

			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		
		$this->load->library("sys/corner_case");
		$corner_case_id	= intval($this->input->get('corner_case_id'));
		$this->corner_case->set_delete_corner_case($corner_case_id);
		echo "<script>history.go(-1)</script>";
	}
	public function media_area_list(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
		
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		
		$this->load->library("common/right_manage");
		$data['update_relate']	=false;
		if ($this->right_manage->check_right("update_relate")) {
			$data['update_relate']	=true;
		}
		$data['delete_relate']	=false;
		if ($this->right_manage->check_right("delete_relate")) {
			$data['delete_relate']=true;
		}
		$data['add_relate']	=false;
		if ($this->right_manage->check_right("add_relate")) {
			$data['add_relate']	=true;
		}
		$data['query_relate']	=false;
		if ($this->right_manage->check_right("query_relate")) {
			$data['query_relate']	=true;
		}
		
		
		$this->load->library("sys/media_area");
		$data['media_area_list'] 	=$this->media_area->query_media_area_list();
		$data['num']				=$this->media_area->query_media_area_num();
		
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/sys_relate_manage/media_area_list?",$data['num']);
		
		$this->load->view("sys/relate/media_area_list",$data);
	}
	public function add_media_area(){
	
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
	
		$this->load->view("sys/relate/add_media_area",$data);
	}
	
	public function save_media_area(){
	
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
	
		$media_area['media_area_name'] =trim($this->input->post("media_area_name"));
		$media_area['create_by']		=$_SESSION['user_name'];
		$media_area['create_time']	=date("Y-m-d H:i:s");
		$media_area['modify_by']		=$_SESSION['user_name'];
		$media_area['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/media_area");
		$result =$this->media_area->save_media_area($media_area);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function edit_media_area(){
	
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
	
		$media_area_id =$this->input->get("media_area_id");
		$this->load->library("sys/media_area");
		$data['media_area_info']=$this->media_area->query_media_area_info($media_area_id);
	
		$this->load->view("sys/relate/edit_media_area",$data);
	}
	
	public function update_media_area(){
	
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
	
		
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_relate",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
			
		}
		
		$media_area_id =$this->input->post('media_area_id');
		$media_area['media_area_name'] 	=trim($this->input->post("media_area_name"));
		$media_area['modify_by']	=$_SESSION['user_name'];
		$media_area['modify_time']	=date("Y-m-d H:i:s");
		$this->load->library("sys/media_area");
		$result =$this->media_area->update_media_area($media_area,$media_area_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	
	public function delete_media_area() {
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
	
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_relate",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		
		$this->load->library("sys/media_area");
		$media_area_id	= intval($this->input->get('media_area_id'));
		$this->media_area->set_delete_media_area($media_area_id);
		echo "<script>history.go(-1)</script>";
	}
	
}